package cn.com.citydo.base.exception;

import java.io.Serializable;

/**
 * 响应结果
 *
 * @author shaodl
 */
public class ResponseResult implements Serializable {

    /**
     * 状态码
     */
    private String code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 结果内容
     */
    private Object result;

    /**
     * 构造器
     */
    public ResponseResult() {
        this.code = String.valueOf(ErrorCodeEnum.SYSTEM_SUCCESS.getCode());
        this.msg = ErrorCodeEnum.SYSTEM_SUCCESS.getMsg();
    }

    /**
     * 构造器
     */
    public ResponseResult(ErrorCodeEnum errorCodeEnum) {
        this.code = String.valueOf(errorCodeEnum.getCode());
        this.msg = errorCodeEnum.getMsg();
    }

    /**
     * 构造器
     */
    public ResponseResult(Integer code, String msg) {
        this.code = code.toString();
        this.msg = msg;
    }

    public static ResponseResult success(Object data) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(String.valueOf(ErrorCodeEnum.SYSTEM_SUCCESS.getCode()));
        responseResult.setMsg(ErrorCodeEnum.SYSTEM_SUCCESS.getMsg());
        responseResult.setResult(data);
        return responseResult;
    }

    /**
     * 构造器
     */
    public ResponseResult(Integer code, String msg, Object result) {
        this.code = code.toString();
        this.msg = msg;
        this.result = result;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder implements Serializable {
        private Integer code;
        private String msg;
        private Object result;

        public Builder code(Integer code) {
            this.code = code;
            return this;
        }

        public Builder msg(String msg) {
            this.msg = msg;
            return this;
        }

        public Builder result(Object result) {
            this.result = result;
            return this;
        }

        public Builder enumres(ErrorCodeEnum errorCodeEnum) {
            this.code = errorCodeEnum.getCode();
            this.msg = errorCodeEnum.getMsg();
            return this;
        }

        public ResponseResult build() {
            if (this.code == null) {
                ResponseResult r = new ResponseResult();
                r.setResult(this.result);
                return r;
            }
            return new ResponseResult(this.code, this.msg, this.result);
        }
    }


}
